package com.czy.daishusys.ui.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.czy.daishusys.R;
import com.czy.daishusys.adapter.DeliverAddressAdapter;
import com.czy.daishusys.entity.DeliverGoodsModel;
import com.czy.daishusys.ui.BaseActivity;
import com.czy.daishusys.widget.RecycleViewDivider;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DeliverAddressActivity extends BaseActivity {


    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.rv_deliver_address)
    RecyclerView rvDeliverAddress;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_deliver_address;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        toolbarTitle.setText(R.string.choose_deliver_address);
        List<DeliverGoodsModel.DataBean.UListBean.AddressListBean> addressList = (List<DeliverGoodsModel.DataBean.UListBean.AddressListBean>) getIntent().getSerializableExtra("addressList");
        DeliverAddressAdapter deliverAddressAdapter = new DeliverAddressAdapter(R.layout.item_deliver_adress_recycler, addressList);
        rvDeliverAddress.setLayoutManager(new LinearLayoutManager(this));
        rvDeliverAddress.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL, R.drawable.shape_line_divider_decoration));
        deliverAddressAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                EventBus.getDefault().post(new DeliverGoodsEvent("address", getIntent().getIntExtra("position", 0), position, "", false));
                finish();
            }
        });
        if (addressList != null) {
            rvDeliverAddress.setAdapter(deliverAddressAdapter);
        }
        View view = LayoutInflater.from(DeliverAddressActivity.this).inflate(
                R.layout.address_footer_view, null);
        deliverAddressAdapter.addFooterView(view);
    }

    @Override
    protected void updateViews() {

    }


}
